/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: webapp-jsf12
 * Description: Implementation of webapp using JSF 1.2
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */

package ru.ffind.webapp.jsf12.conv;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 * Converter for numberic representation of IP address.
 * Like INET_ATON, INET_NTOA in MySQL.
 *
 * @author Rage Steel
 */
public class InetConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        // inet_ntoa
        int address = (Integer) value;

        return String.format("%d.%d.%d.%d",
                (address >> 24) & 0xFF,
                (address >> 16) & 0xFF,
                (address >> 8) & 0xFF,
                address & 0xFF);
    }

}
